package com.example.pinkcat;

import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.pinkcat.adapter.Fenqu_qm_adapter;
import com.example.pinkcat.api.getData.getData_waibu;

import java.util.Objects;

public class Fenqu_activity extends AppCompatActivity {
    Context context  = this;

    String[] mtitle = new String[]{
            "科技","综艺",
            "电视剧","电影",
            "体育","美食",
            "动漫","舞蹈",
            "游戏","汽车",
            "音乐","生活",
            "娱乐"};


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        Objects.requireNonNull(getSupportActionBar()).hide();//去掉标题栏
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
//                WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN| View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }//深色信息栏

        setContentView(R.layout.activity_fenqu_qm);

        Intent intent =getIntent();
        String agreementTitle = "fq";
        if (intent!=null){
            agreementTitle=intent.getStringExtra("agreementTitle");
        }

        if (agreementTitle==null) agreementTitle="fq";
        RecyclerView recyclerView=findViewById(R.id.fenqu_qm_RV);
        recyclerView.setLayoutManager(new LinearLayoutManager(context));

        TextView fenqu_tx = findViewById(R.id.fenqu_qm_tx);
        Fenqu_qm_adapter adapter;
        adapter=new Fenqu_qm_adapter(context,1);

        if (agreementTitle.equals("科技")){
            fenqu_tx.setText(mtitle[0]);
            getData_waibu.getVideotype(context,adapter,"科技");
        }
        else if (agreementTitle.equals("综艺")){
            fenqu_tx.setText(mtitle[1]);
            getData_waibu.getVideotype(context,adapter,"综艺");
        }
        else if (agreementTitle.equals("电视剧")){
            fenqu_tx.setText(mtitle[2]);
            getData_waibu.getVideotype(context,adapter,"电视剧");
        }
        else if (agreementTitle.equals("电影")){
            fenqu_tx.setText(mtitle[3]);
            getData_waibu.getVideotype(context,adapter,"电影");
        }
        else if (agreementTitle.equals("体育")){
            fenqu_tx.setText(mtitle[4]);
            getData_waibu.getVideotype(context,adapter,"体育");
        }
        else if (agreementTitle.equals("美食")){
            fenqu_tx.setText(mtitle[5]);
            getData_waibu.getVideotype(context,adapter,"美食");
        }
        else if (agreementTitle.equals("动漫")){
            fenqu_tx.setText(mtitle[6]);
            getData_waibu.getVideotype(context,adapter,"动漫");
        }
        else if (agreementTitle.equals("舞蹈")){
            fenqu_tx.setText(mtitle[7]);
            getData_waibu.getVideotype(context,adapter,"舞蹈");
        }
        else if (agreementTitle.equals("游戏")){
            fenqu_tx.setText(mtitle[8]);
            getData_waibu.getVideotype(context,adapter,"游戏");
        }
        else if (agreementTitle.equals("汽车")){
            fenqu_tx.setText(mtitle[9]);
            getData_waibu.getVideotype(context,adapter,"汽车");
        }
        else if (agreementTitle.equals("音乐")){
            fenqu_tx.setText(mtitle[10]);
            getData_waibu.getVideotype(context,adapter,"音乐");
        }
        else if (agreementTitle.equals("生活")){
            fenqu_tx.setText(mtitle[11]);
            getData_waibu.getVideotype(context,adapter,"生活");
        }
        else if (agreementTitle.equals("娱乐")){
            fenqu_tx.setText(mtitle[12]);
            getData_waibu.getVideotype(context,adapter,"娱乐");
        }

        recyclerView.setAdapter(adapter);

        findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        if (newConfig.fontScale != 1)//非默认值
            getResources();
        super.onConfigurationChanged(newConfig);
    }

    @Override
    public Resources getResources() {
        Resources res = super.getResources();
        if (res.getConfiguration().fontScale != 1) {//非默认值
            Configuration newConfig = new Configuration();
            newConfig.setToDefaults();//设置默认
            res.updateConfiguration(newConfig, res.getDisplayMetrics());
        }
        return res;
    }
}
